package com.yfy.model.mapper;


import com.yfy.model.entity.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author yfy2001
 * @date 2022/11/15 12:23
 */
@Mapper
public interface CommentMapper {
    /**
     * 评论列表查询
     * @return
     */
    @Select("SELECT * FROM t_comment ORDER BY id DESC")
    public List<Comment> selectAllCommentWithPage();

    // 分页展示某个文章的评论
    @Select("SELECT * FROM t_comment WHERE article_id=#{aid} ORDER BY id DESC")
    public List<Comment> selectCommentWithPage(Long aid);

    // 后台查询最新几条评论
    @Select("SELECT * FROM t_comment ORDER BY id DESC")
    public List<Comment> selectNewComment();

    // 发表评论
    @Insert("INSERT INTO t_comment (creator,modifier,gmt_created,gmt_modified,is_deleted,article_id,ip,content,author)" +
            " VALUES (#{creator}, #{modifier},#{gmtCreated},#{gmtModified},#{isDeleted},#{articleId},#{ip},#{content},#{author})")
    public void pushComment(Comment comment);

    // 站点服务统计，统计评论数量
    @Select("SELECT COUNT(1) FROM t_comment")
    public Integer countComment();

    // 通过文章id删除评论信息
    @Delete("DELETE FROM t_comment WHERE article_id=#{aid}")
    public void deleteCommentWithId(Long aid);

    /**
     * 通过id删除评论
     * @param id
     */
    @Delete("DELETE FROM t_comment WHERE id=#{id}")
    public void deleteComment(Long id);

    /**
     * 通过id查询一条评论
     * @param id
     * @return
     */
    @Select("SELECT * FROM t_comment WHERE id=#{id}")
    public Comment selectCommentWithId(Long id);


}
